﻿using Sasa.QualityTools.CodeAnalysis.Common;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Options
{
    public class GeneralOption
    {
        private GeneralOptionPageData optionPage;


        public string FxCopCmdPath
        {
            get
            {
                return optionPage.FxCopCmdPath;
            }
            set
            {
                optionPage.FxCopCmdPath = value;
            }
        }

        [SuppressMessage("Microsoft.Design", "CA1031")]
        public Version FxCopVersion
        {
            get
            {
                try
                {
                    return AssemblyName.GetAssemblyName(optionPage.FxCopCmdPath).Version;
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Failed to load FxCopCmd.exe from '{0}'.", optionPage.FxCopCmdPath);
                    return new Version();
                }
            }
        }

        public string MetricsPath
        {
            get
            {
                return optionPage.MetricsPath;
            }
            set
            {
                optionPage.MetricsPath = value;
            }
        }

        public Version MetricsVersion
        {
            get
            {
                try
                {
                    return AssemblyName.GetAssemblyName(optionPage.MetricsPath).Version;
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Failed to load Metrics.exe from '{0}'.", optionPage.MetricsPath);
                    return new Version();
                }
            }
        }

        public bool UseExternalWebBrowser
        {
            get
            {
                return optionPage.UseExternalWebBrowser;
            }
        }

        public IntegratedCodeAnalysisCommandBehaviors IntegratedCodeAnalysisCommandBehavior
        {
            get
            {
                return optionPage.IntegratedCodeAnalysisCommandBehavior;
            }
        }


        public GeneralOption(GeneralOptionPageData optionPage)
        {
            this.optionPage = optionPage;
        }
    }
}
